package com.htc.android.footprints.utils.voice;

import java.io.IOException;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;

public class VoicePlayer
{
  public static final int STATE_ERROR = -1;
  public static final int STATE_IDLE = 1;
  public static final int STATE_PAUSE = 3;
  public static final int STATE_PLAYING = 2;
  public static final int STATE_PLAY_COMPLETE = 10;
  private static final String TAG = "VoicePlayer";
  MediaPlayer.OnCompletionListener completelistener = new MediaPlayer.OnCompletionListener()
  {
    public void onCompletion(MediaPlayer paramMediaPlayer)
    {
      VoicePlayer.this.mOnPlayerStateChangedListener.OnComplete(10);
      VoicePlayer.this.seek(0L);
      VoicePlayer.this.start();
    }
  };
  MediaPlayer.OnErrorListener errorListener = new MediaPlayer.OnErrorListener()
  {
    public boolean onError(MediaPlayer paramMediaPlayer, int paramInt1, int paramInt2)
    {
      switch (paramInt1)
      {
      default:
      case 100:
      }
      for (int i = 0; ; i = 1)
      {
        return i;
        VoicePlayer.access$002(VoicePlayer.this, false);
        VoicePlayer.this.mMediaPlayer.release();
        VoicePlayer.access$102(VoicePlayer.this, new MediaPlayer());
        VoicePlayer.this.mOnPlayerStateChangedListener.OnError(100);
      }
    }
  };
  public int mCurrentState = 1;
  private Handler mHandler;
  private boolean mIsInitialized = false;
  private MediaPlayer mMediaPlayer = new MediaPlayer();
  private OnPlayerStateChangedListener mOnPlayerStateChangedListener;

  private void setState(int paramInt)
  {
    this.mCurrentState = paramInt;
    this.mOnPlayerStateChangedListener.OnPlayerStateChanged(paramInt);
  }

  public void closeVoicePlayer()
  {
    if (this.mMediaPlayer != null)
    {
      this.mMediaPlayer.stop();
      this.mMediaPlayer.release();
      this.mMediaPlayer = null;
    }
  }

  public long duration()
  {
    return this.mMediaPlayer.getDuration();
  }

  public boolean isInitialized()
  {
    return this.mIsInitialized;
  }

  public boolean isPlaying()
  {
    return this.mMediaPlayer.isPlaying();
  }

  public void pause()
  {
    this.mMediaPlayer.pause();
    setState(3);
  }

  public long position()
  {
    return this.mMediaPlayer.getCurrentPosition();
  }

  public void preparePlay(String paramString)
  {
    setDataSource(paramString);
  }

  public void restoreState(Bundle paramBundle)
  {
  }

  public long seek(long paramLong)
  {
    this.mMediaPlayer.seekTo((int)paramLong);
    return paramLong;
  }

  public void setDataSource(String paramString)
  {
    try
    {
      this.mMediaPlayer.reset();
      this.mMediaPlayer.setDataSource(paramString);
      this.mMediaPlayer.setOnCompletionListener(this.completelistener);
      this.mMediaPlayer.setOnErrorListener(this.errorListener);
      this.mMediaPlayer.prepare();
      this.mIsInitialized = true;
      return;
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        this.mIsInitialized = false;
        this.mOnPlayerStateChangedListener.OnError(-1);
      }
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      while (true)
      {
        this.mIsInitialized = false;
        this.mOnPlayerStateChangedListener.OnError(-1);
      }
    }
  }

  public void setHandler(Handler paramHandler)
  {
    this.mHandler = paramHandler;
  }

  public void setPlayerStateChangedListener(OnPlayerStateChangedListener paramOnPlayerStateChangedListener)
  {
    if (paramOnPlayerStateChangedListener != null)
      this.mOnPlayerStateChangedListener = paramOnPlayerStateChangedListener;
  }

  public void start()
  {
    this.mMediaPlayer.start();
    setState(2);
  }

  public void stop()
  {
    this.mMediaPlayer.reset();
    this.mIsInitialized = false;
    setState(1);
  }

  public static abstract interface OnPlayerStateChangedListener
  {
    public abstract void OnComplete(int paramInt);

    public abstract void OnError(int paramInt);

    public abstract void OnPlayerStateChanged(int paramInt);
  }
}

/* Location:           E:\workspace\dex2java\dex-translator-0.0.9.3\HtcFootprints_dex2jar.jar
 * Qualified Name:     com.htc.android.footprints.utils.voice.VoicePlayer
 * JD-Core Version:    0.6.0
 */